//
//  HotViewcontroller.m
//  YSBEmployee
//
//  Created by developer on 2021/11/30.
//  Copyright © 2021 ysb. All rights reserved.
//


#import "YSBEmployerHomeController.h"

#import "YSBOrderListHomeMainViewController.h"

#import "YSBSwitchWorkTitleCTypeView.h"

#import "YSBMessageListTableViewCell.h"

#import "YSBHomeWorkOrderView.h"

#import "YSBMediationAllModel.h"

#import "YSBMediationDetailsViewController.h"

#import "HttpClient.h"

#import "YSBSwitchWorkCenterTitlesView.h"

#import "YSBCollectionMainViewController.h"


#pragma mark - 修改收藏订单里面的文字和滑动功能
@implementation YSBCollectionMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"收藏的订单";

    [self configuration];

    self.ctrlContanier.scrollEnabled = NO;

}

@end


@implementation YSBSwitchWorkCenterTitlesView

- (UILabel *)rightTitleLabel{
    if (!_rightTitleLabel) {
        _rightTitleLabel = [[UILabel alloc] init];
        _rightTitleLabel.textAlignment = self.leftTitleLabel.textAlignment;
        _rightTitleLabel.font = self.leftTitleLabel.font;
        _rightTitleLabel.textColor = self.leftTitleLabel.textColor;
        _rightTitleLabel.text = @"当面结";
    }
    return _rightTitleLabel;
}

@end




@implementation HttpClient

#pragma mark - 修改升级功能,去除请求苹果官网
- (void)updateMethodWithStrive:(BOOL)needStrive andUpdateContent:(NSArray *)updateContentArray andUpdateModel:(UpdateModel *)model {
    
    //获取服务器上应用的最新版本号
    NSString *updateVersion = [YSBCommonTool isBlankString:model.version_no] ? @"" : model.version_no;
    
    NSDictionary *info= [[NSBundle mainBundle] infoDictionary];
    NSString *bundleVersion = [YSBCommonTool isBlankString:info[@"CFBundleShortVersionString"]] ? @"" : info[@"CFBundleShortVersionString"];
    
    NSString *messageStr = [NSString stringWithFormat:@"发现新版本(%@),是否更新?", updateVersion];
    if (updateContentArray.count > 0) {
        NSString *updateStr = @"";
        if (updateContentArray.count > 1) {
            updateStr = [updateContentArray componentsJoinedByString:@" \n"];
        }else{
            updateStr = updateContentArray[0];
        }
        messageStr = updateStr;
    }
    
    if ([updateVersion isEqualToString:bundleVersion]) {
        //            GSToastInCenter(@"当前版本为最新版本无需更新！");
    }
    else {
        if (self.updateAlert == nil) {
            self.updateAlert = [SELUpdateAlert showUpdateAlertWithVersion:updateVersion Description:messageStr isForcingUpdate:needStrive];
            self.updateAlert.hidden = YES;
            //添加弹框界面
            if (self.updateAlert) {
                self.updateAlert.tag = 1;
                [[YSBMSAlertManager shareManager] addAlert:self.updateAlert];
            }
        }
    }
    
}


@end



@interface YSBMediationDetailModel : NSObject

#pragma mark - 给中介订单详情模型添加interview_id
//报名求职id
@property (assign, nonatomic) NSInteger interview_id;





@end


@implementation YSBMediationDetailsViewController

#pragma mark - 给中介订单详情模型添加interview_id
//取消订单
- (void)goToMediationCancelSignUpWithModel:(YSBMediationDetailModel *)detailModel {
    
    __block NSMutableDictionary *tempMutDict = [[NSMutableDictionary alloc] init];
    
    NSLog(@"self.bottomView.detailModel.interview_id = %ld",self.bottomView.detailModel.interview_id);
    
    if (self.interview_id > 0) {
        [tempMutDict setObject:@(self.interview_id) forKey:@"interview_id"];
    }
    else if (self.bottomView.detailModel.interview_id > 0) {
        self.interview_id = self.bottomView.detailModel.interview_id;
        [tempMutDict setObject:@(self.interview_id) forKey:@"interview_id"];
    }
    
    self.cancelReasonVC.myClickBlock = ^(NSString *reason) {
        if (![YSBCommonTool isBlankString:reason]) {
            [tempMutDict setObject:reason forKey:@"cancel_reason"];
        }
        [self.vm.cancelCommand execute:@[tempMutDict,detailModel]];
    };
    self.cancelReasonVC.isReset = YES;
    self.cancelReasonVC.titleStr = @"取消订单";
    self.cancelReasonVC.comeFromType = 1005;
    self.cancelReasonVC.modalPresentationStyle = 4;
    [self presentViewController:self.cancelReasonVC animated:YES completion:NULL];
    
}

@end





@implementation YSBHomeWorkOrderView

#pragma mark - 修改首页匹配到临时工订单的标题高度计算
- (void)updateHomeWorkOrderViewTap {
    
    CGFloat mWidth = [[UIScreen mainScreen] bounds].size.width - 110;
    id objectHeight = [[NSObject alloc] init];
    
    CGFloat tHeight = 20;
    CGFloat dHeight = [YSBCommonTool heightOfString:self.model.title font:[UIFont boldSystemFontOfSize:15] width:mWidth];
    if (dHeight > 20) {
        tHeight = dHeight;
    }
    objectHeight = @(tHeight);
    
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(objectHeight);
    }];
    
}

@end



#pragma mark - 订单列表增加兼容性判断处理视图
@implementation YSBOrderListHomeMainViewController

- (void)resetTitleView {

    CGFloat mWidth = [[UIScreen mainScreen] bounds].size.width - 110;
    self.switchWorkTypeView.frame = CGRectMake(0, 0, mWidth, 44);
    
    self.navigationItem.titleView = self.switchWorkTypeView;
    
    NSString *version = [UIDevice currentDevice].systemVersion;
    if (version.doubleValue >= 11.0) {//iOS11及以上系统才能使用masonry布局UINaviationBar,否则会崩溃
        YSBSwitchWorkTitleCTypeView *switchWorkTypeView = [[YSBSwitchWorkTitleCTypeView alloc] init];
        switchWorkTypeView = self.switchWorkTypeView;
        [switchWorkTypeView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.navigationItem.titleView).offset(0);
            make.bottom.mas_equalTo(self.navigationItem.titleView).offset(0);
            make.height.mas_equalTo(@(44));
            make.width.mas_equalTo(@(280));
        }];
    }
    
}


#pragma mark - 修改扫一扫按钮,进入下一级页面返回后会隐藏的问题
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
        
    if (self.temporaryIndex > 0) {//切换线上结订单列表状态
        [self switchingTemporaryStatusWithIndex:self.temporaryIndex];
    }
    if (self.offlineIndex > 0) {//切换线下结订单列表状态
        [self switchingOfflineStatusWithIndex:self.offlineIndex];
    }
    
    
    self.rightItemButton.hidden = (self.myCategoryView.defaultSelectedIndex == 0) ? NO : YES;

    
}

- (instancetype)init {
    self = [super init];
    if (self) {
        self.titles = @[@"日结工", @"当面结",@"找中介"];
    }
    return self;
}


@end


#pragma mark - 消息列表按钮事件添加block判空
@implementation YSBMessageListTableViewCell

//按钮事件
- (void)rightFirstBtnAction {
    if (self.btnClickBlock) {
        self.btnClickBlock(self.model);
    }
}


@end


#pragma mark - 修改首页菜单显示菜单宽度由文字长度决定
@implementation YSBEmployerHomeController

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat textWidth = 0;
    
    if (self.menuModelArray.count > 0) {
        JXCategorySubtitleCellModel *model = self.menuModelArray[indexPath.item];
        textWidth = model.titleFont.pointSize * (model.title.length) + 4;
        
        CGFloat subtitleWidth = model.subtitleFont.pointSize * (model.subtitle.length) + 16;
        textWidth = textWidth > subtitleWidth ? textWidth : subtitleWidth;
        
    }
    
    NSInteger count = self.menuModelArray.count == 0 ? 1 : self.menuModelArray.count;
    CGFloat dWidth = ([[UIScreen mainScreen] bounds].size.width - 20 - 10 * (count - 1)) / count;
    
    CGFloat tWidth = textWidth < dWidth ? dWidth : textWidth;
    
    return CGSizeMake(tWidth, 50);
 
}


@end






#pragma mark - 修改列表标题
@implementation YSBSwitchWorkTitleCTypeView

- (UILabel *)leftTitleLabel{
    if (!_leftTitleLabel) {
        _leftTitleLabel = [[UILabel alloc] init];
        _leftTitleLabel.textAlignment = 1;
        _leftTitleLabel.font = [UIFont boldSystemFontOfSize:18];
        _leftTitleLabel.textColor = [UIColor blackColor];
        _leftTitleLabel.adjustsFontSizeToFitWidth = YES;
        _leftTitleLabel.text = @"日结工";
    }
    return _leftTitleLabel;
}

- (UILabel *)rightTitleLabel{
    if (!_rightTitleLabel) {
        _rightTitleLabel = [[UILabel alloc] init];
        _rightTitleLabel.textAlignment = 1;
        _rightTitleLabel.font = [UIFont boldSystemFontOfSize:14];
        _rightTitleLabel.textColor = [UIColor lightGrayColor];
        _rightTitleLabel.adjustsFontSizeToFitWidth = YES;
        _rightTitleLabel.text = @"当面结";
    }
    return _rightTitleLabel;
}


- (UILabel *)thirdTitleLabel{
    if (!_thirdTitleLabel) {
        _thirdTitleLabel = [[UILabel alloc] init];
        _thirdTitleLabel.textAlignment = 1;
        _thirdTitleLabel.font = [UIFont boldSystemFontOfSize:14];
        _thirdTitleLabel.textColor = [UIColor lightGrayColor];
        _thirdTitleLabel.adjustsFontSizeToFitWidth = YES;
        _thirdTitleLabel.text = @"找中介";
    }
    return _thirdTitleLabel;
}

@end
